/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webbucks;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ghaban
 */
public class SupplyBean {
    List<Ingredient> ingredients = new ArrayList<Ingredient>();
            String url = "jdbc:mysql://localhost:8889/";
        String dbName = "webbucks";
        String driver = "com.mysql.jdbc.Driver";
        String user = "root"; 
        String pw = "root";
        
        public SupplyBean(){
        try {
            Class.forName(driver).newInstance();
            Connection con=DriverManager.getConnection(url+dbName,user,pw);
            String Query = "Select * from ingredients order by name";
            Statement stmt = con.createStatement();
            ResultSet srs = stmt.executeQuery(Query);
            int currentQuantity;
            String currentName;
            while (srs.next()) {
             currentName = srs.getString("name");
             currentQuantity = srs.getInt("supply");
             ingredients.add(new Ingredient(currentName, currentQuantity));
            }
            con.close();
        }
        catch( Exception e ){
            System.out.println("Something went wrong" + e.toString() );
        }
    }
    public List<Ingredient> getIngredients() {
        return ingredients;    
    }   
}
